package com.situ.day2;

import org.junit.Test;

import java.util.Scanner;

public class WhileForSwitchDemo {
    @Test
    public void test1(){
        //  while,for
        int i=  1;
        while (i <= 5){
            System.out.println("HelloWorld");
            i++;
        }
    }

    @Test
    public void test2(){
        for(int i  = 1;i <= 5;i++) {
            System.out.println("HelloWorld");
        }
    }

    //1.累加思想（1+2+3+...+100）
    @Test
    public void test3(){
        int sum = 0;
        for (int i = 1;i <= 100;i++) {
            System.out.println(i);
            sum += i;
            System.out.println("sum:"+sum);
        }
        System.out.println("sum:"+sum);
    }

    //统计思想，数一下符合条件的有多少个（计算1-100以内7的倍数的个数）
    public void test4(){
        int count = 0;
        for (int i = 1;i  <= 100;i++){
            if(i % 7 ==0){
                System.out.println(i);
                count++;
            }
        }
    }

    @Test
    public void test55() {
        //****
        for (int i = 1; i <= 4; i++) {
            System.out.print("*");
        }
        System.out.println();
        //*
        //*
        //*
        //*
        for (int i = 1; i <= 4; i++) {
            System.out.println("*");
        }
    }

    @Test
    public void test6() {
        // i=1代表打印第一行
        for (int i = 1; i <= 3; i++) {
            //i=1时候里面的循环打印第一行的四个星号
            for (int j = 1; j <= 4; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    @Test
    public void test7() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j + "x" + i + "="+ (i *  j) +"\t");
            }
            System.out.println();
        }
    }

    @Test
    public void test8() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 10 - i; j++) {
                System.out.print(j + "x" + i + "="+ (i *  j) +"\t");
            }
            System.out.println();
        }
    }

    @Test
    public void test9() {
        int num = 2;
        if (num == 1) {
            System.out.println("1");
        } else if (num == 2) {
            System.out.println("2");
        } else if (num == 3) {
            System.out.println("3");
        } else {
            System.out.println("else");
        }

        switch (num){
            case 1:
                System.out.println("1");
                break;
            case 2:
                System.out.println("2");
                break;
            case 3:
                System.out.println("3");
                break;
            default:
                System.out.println("default");
                break;
        }
    }

    //输入月份、年份判断天数
    @Test
    public void test10(){
        Scanner scanner1 = new Scanner(System.in);
        Scanner scanner2 = new Scanner(System.in);
        System.out.println("请输入年份：");
        System.out.println("请输入月份：");
        int year = scanner1.nextInt();
        int month = scanner2.nextInt();
        if(month < 0 || month > 12){
            System.out.println("月份非法");
            return;
        }
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                System.out.println(year + "年" + month + "月有31天");
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                System.out.println(year + "年" + month + "月有30天");
                break;
            case 2:
                if (year % 4 == 0 && year % 100 != 0) {
                    System.out.println(year + "年" + month + "月有28天");
                } else {
                    System.out.println(year + "年" + month + "月有29天");
                }
                break;
        }
    }

    @Test
    public void test11() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入成绩：");
        int score = scanner.nextInt();
        //卫语句1
        if(score < 0 || score > 100){
            System.out.println("这是非法输入");
            //方法后面的代码不再执行
            return;
        }

    }
}
